package com.example.demo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
import org.springframework.transaction.support.TransactionTemplate;

@SpringBootApplication
@Slf4j
public class DemoApplication implements CommandLineRunner {
	@Autowired
	private TransactionTemplate transactionTemplate;
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Autowired
	EmpService empService;

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Override
	public void run(String... args) throws Exception {
		empService.insert();
		try {
			empService.backInsert();
		} catch (Exception e) {
			e.printStackTrace();
		}
		try {
			empService.invokeBackInsert();
		} catch (Exception e) {
			e.printStackTrace();
		}
		empService.findAll();
//		transactionTemplate.execute(new TransactionCallbackWithoutResult() {
//			@Override
//			protected void doInTransactionWithoutResult(TransactionStatus transactionStatus) {
//				jdbcTemplate.update("insert into t_student(name) values(?)",new Object[]{"yq"});
//				transactionStatus.setRollbackOnly();
//				log.info("comm = {}",transactionStatus.isCompleted());
//			}
//		});
//		jdbcTemplate.queryForList("select * from t_student").forEach(m->log.info(m.toString()));
	}



}
